package com.digitalchina.lxnsy.activity.old;

import android.graphics.Color;
import androidx.viewpager.widget.ViewPager;
import android.view.View;
import android.widget.TextView;

import com.digitalchina.lxnsy.R;
import com.digitalchina.lxnsy.adapter.TabViewPagerAdapter;
import com.digitalchina.lxnsy.base.BaseActivity;
import com.digitalchina.lxnsy.entity.PagerItemVO;
import com.digitalchina.lxnsy.fragment.MyAttentionTeacherFragment;
import com.digitalchina.lxnsy.fragment.MyAttentionTrainingFragment;

import java.util.ArrayList;
import java.util.List;

import butterknife.Bind;
import butterknife.OnClick;

public class MyAttentionActivity extends BaseActivity {

    @Bind(R.id.my_attention_viewpager)
    ViewPager myAttentionViewpager;
    @Bind(R.id.attention_tv_left_tab)
    TextView attentionTvLeftTab;
    @Bind(R.id.attention_tv_right_tab)
    TextView attentionTvRightTab;

    private List<PagerItemVO> mList = new ArrayList<>();
    private final int TAB_LEFT = 0;
    private final int TAB_RIGHT = 1;
    MyAttentionTeacherFragment attentionExpertFragment;

    @Override
    public void setLayout() {
        setTitle("我的关注");
        setContentLayout(R.layout.activity_my_attention);
    }

    @Override
    public void initMember() {
        mList.add(new PagerItemVO("培训", new MyAttentionTrainingFragment()));
        mList.add(new PagerItemVO("教师", attentionExpertFragment = new MyAttentionTeacherFragment()));

        myAttentionViewpager.setAdapter(new TabViewPagerAdapter(getFragmentManager(), mList));
    }

    @OnClick({R.id.attention_tv_left_tab, R.id.attention_tv_right_tab})
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.attention_tv_left_tab:
                updateTabStatus(TAB_LEFT);
                myAttentionViewpager.setCurrentItem(TAB_LEFT);
                break;
            case R.id.attention_tv_right_tab:
                updateTabStatus(TAB_RIGHT);
                myAttentionViewpager.setCurrentItem(TAB_RIGHT);
                break;
        }
    }

    private void updateTabStatus(int index) {
        switch (index) {
            case TAB_LEFT:
                attentionTvLeftTab.setBackgroundResource(R.drawable.shape_left_rec_circle_grey);
                attentionTvRightTab.setBackgroundResource(R.drawable.shape_right_rec_circle_white);
                attentionTvLeftTab.setTextColor(Color.WHITE);
                attentionTvRightTab.setTextColor(0xff37B5B4);
                break;
            case TAB_RIGHT:
                attentionTvLeftTab.setBackgroundResource(R.drawable.shape_left_rec_circle_white);
                attentionTvRightTab.setBackgroundResource(R.drawable.shape_right_rec_circle_grey);
                attentionTvLeftTab.setTextColor(0xff37B5B4);
                attentionTvRightTab.setTextColor(Color.WHITE);
                break;
        }
    }

    @Override
    public void addListener() {
        myAttentionViewpager.addOnPageChangeListener(new ViewPager.OnPageChangeListener() {
            @Override
            public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {

            }

            @Override
            public void onPageSelected(int position) {
                updateTabStatus(position);
            }

            @Override
            public void onPageScrollStateChanged(int state) {

            }
        });
    }

    /**
     * 通知对应的关注专家fragment刷新数据
     */
    public void notifyToRefresh() {
        attentionExpertFragment.onRefresh();
    }

    @Override
    public void rightOnClick() {

    }

    @Override
    public void setHandler() {

    }

    @Override
    public void callBack(Object object) {

    }
}
